import queryString from 'querystring'
//统一处理表单post请求
export default (req,res,next) => {
  //如果是get请求，不作处理
  if(req.method.toLowerCase() == 'get'){
    return next()
  }
  //若果是带文件的请求，不作处理
  if(req.headers['content-type'].startsWith('multipart/form-data')){
    return next()
  }
  let data = ''
  req.on('data',chunk => {
    data += chunk
  })
  req.on('end',() => {
    req.body = queryString.parse(data)
    next()
  })
}